import Request from '../common/js/request'

// 流程定义接口
class FlowDesignService {
  /**
   * 根据条件查询流程定义列表
   * @param {resourceName} form 资源名称
   * @param {name} from 部署名称
   * @param pageNum 当前页数
   * @param pageSize 每页条数
   */
  static getProcessDefinitionListByCondition(form, pageNum, pageSize) {
    const url = '/api-workflow/repository/getProcessDefinitionListByCondition'

    const data = {
      resourceName: form && form.resourceName,
      name: form && form.name,
      pageNum: pageNum - 1,
      pageSize
    }

    return Request.get(url, data)
  }

  /**
   * 根据定义ID查询流程定义详情
   * @param definitionId 定义ID
   */
  static getProcessDefinitionByDefinitionId(definitionId) {
    const url = '/api-workflow/repository/getProcessDefinitionByDefinitionId'

    const data = {
      definitionId
    }

    return Request.get(url, data)
  }

  /**
   * 流程部署
   * @param resourceName 资源名称
   * @param typeId 类型Id
   * @param name 部署名称
   * @param text 部署内容
   */
  static processDeployment(resourceName, typeId, name, text) {
    const url = '/api-workflow/repository/processDeployment'

    const data = {
      resourceName,
      typeId,
      name,
      text
    }

    return Request.post(url, data)
  }

  /**
   * 删除流程部署
   * @param key 定义key
   */
  static deleteProcessDeployment(key) {
    const url = '/api-workflow/repository/deleteProcessDeployment'

    const data = {
      key
    }

    return Request.post(url, data)
  }

  /**
   * 流程挂起或激活
   * @param definitionId 定义ID
   */
  static processPauseOrStart(definitionId) {
    const url = '/api-workflow/repository/processPauseOrStart'

    const data = {
      definitionId
    }

    return Request.post(url, data)
  }
}

export default FlowDesignService
